#!/bin/bash

# Slackware build script for jfsw_wanton_destruction

# Written by B. Watson (yalhcru@gmail.com)

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# The 'source' file is a self-extracting zip file for DOS/Windows.
# VERSION is the timestamp of the newest file inside the archive (the
# readme.txt, written when the freeware release was made).

# Upstream's only license-like text is: This add-on is provided "as is",
# and is released as freeware.

# The original download links are all fileplanet-like services, with no
# registration or even captcha required. I self-hosted the archive to
# guarantee a stable download link.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=jfsw_wanton_destruction
VERSION=${VERSION:-20050909}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

ARCH=noarch

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
mkdir -p $PRGNAM-$VERSION
cd $PRGNAM-$VERSION
unzip $CWD/swwd.exe '*.GRP' '*.txt' '*.ico'
chown -R root:root .
chmod 644 *

mkdir -p $PKG/usr/share/games/jfsw
cp -a WT.GRP $PKG/usr/share/games/jfsw/wt.grp

sed -i 's,\r,,' *.txt
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a *.txt *.ico $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/README > $PKG/usr/doc/$PRGNAM-$VERSION/README_SBo.txt
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE
